package com.imc.platform.base.login.controller;

import com.imc.core.annotation.Logs;
import com.imc.core.utils.RandomValidateCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by tanweiping on 2018/8/2.
 */
/*
* 类描述：登陆控制器
* 开发者：tanweiping
* 创建日期：2018/8/7 10:31
*/
@Slf4j
@Controller
public class LoginController {

    /*
    * tanweiping  2018/8/7 10:32
    * 方法描述：登陆页面
    */
    @GetMapping("/login/index")
    public String loginPage() {
        return "base/login/login";
    }

    /*
    * tanweiping  2018/8/7 14:39
    * 方法描述：注册页面
    */
    @GetMapping("/login/register")
    public String register(){
        return "base/login/register";
    }

    @GetMapping("/login/draftCaptcha")
    public String draftCaptcha(){
        return "base/login/draftCaptcha";
    }

    /*
    * tanweiping  2018/8/7 10:32
    * 方法描述：登陆相关的错误页面
    */
    @GetMapping("/login/error")
    public String errorPage(Model model,
                            @RequestParam(defaultValue = "500") String errorCode,
                            @RequestParam(defaultValue = "服务器异常") String errorMessage) {
        model.addAttribute("errorCode", errorCode).addAttribute("errorMessage", errorMessage);
        return "frame/fm/error";
    }

    /*
    * tanweiping  2018/8/7 10:32
    * 方法描述：生成验证码
    */
    @Logs(label = "生成验证码异常")
    @GetMapping("/login/getVerify")
    public void getVerify(HttpServletRequest request, HttpServletResponse response) {
            response.setContentType("image/jpeg");//设置相应类型,告诉浏览器输出的内容为图片
            response.setHeader("Pragma", "No-cache");//设置响应头信息，告诉浏览器不要缓存此内容
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expire", 0);
            RandomValidateCodeUtil randomValidateCode = new RandomValidateCodeUtil();
            randomValidateCode.getRandcode(request, response);//输出验证码图片方法
    }

}
